<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <script src="js/jquery-1.11.2.min.js"></script>
    <script src="js/clipboard.min.js"></script>
    <title>复制到剪贴板！</title>
</head>
<body>
<p>居然可以这样！<span id="foo">这是复制的内容，嘿嘿！</span></p>
<button class="btn" data-clipboard-action="copy" data-clipboard-target="#foo" id="copy_btn">
    复制按钮
</button>

</body>
<script>
    $(document).ready(function(){
        var fooText=$("#foo").text();
        var clipboard = new Clipboard('#copy_btn');

        clipboard.on('success', function(e) {
            console.info('Action:', e.action);
            console.info('Text:', e.text);
            console.info('Trigger:', e.trigger);
            alert("复制成功");

            e.clearSelection();
        });
    });
</script>
</html>  